package com.sdp.irrigation.controller;


import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sdp.core.bizc.vo.Result;
import com.sdp.irrigation.db.irrigation_operate.service.IIrrigationOperateService;
import com.sdp.irrigation.entity.IrrigationOperate;

/**
 * <p>
 * 操作说明 前端控制器
 * </p>
 *
 * @author zsp
 * @since 2025-03-01
 */
@RestController
@RequestMapping("/IrrigationOperateController")
public class IrrigationOperateController {

	@Autowired
	private IIrrigationOperateService iIrrigationOperateService;
 

	@GetMapping(value="/queryOperate")
	public Result<?> queryOperate() {
		LambdaQueryWrapper<IrrigationOperate> queryWrapper = new LambdaQueryWrapper<>();
		IrrigationOperate operate = iIrrigationOperateService.getOne(queryWrapper,false);
		if(operate==null) {
			operate= new IrrigationOperate();
		}
		return Result.ok(operate);
	}
	
	@PostMapping(value = "/save")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> save(@RequestBody IrrigationOperate operate) {
		if(operate==null) {
			return Result.error("操作说明信息为空");
		}
		operate.setUpdateTime(LocalDateTime.now());
		if(StringUtils.isEmpty(operate.getKeyId())) {
			operate.setCreateTime(LocalDateTime.now());
			iIrrigationOperateService.save(operate);
		}else {
			iIrrigationOperateService.updateById(operate);
		}
		
		return Result.ok(operate);
	}
}

